<template>
  <div>
    <div class="wrapper" ref="wrapper">
      <div class="content">
        <slot></slot>
      </div>
    </div>
  </div>
</template>
<script>
import BScroll from "better-scroll";
export default {
  name: "Bscroll",
  props: {
    probeType: {
      type: Number,
      default: 0,
    },
    // pullUpLoad: {
    //   type: Boolean,
    //   default: false,
    // },
  },
  data() {
    return {
      scroll: null,
    };
  },
  methods: {
    scrollTo(x, y, time = 300) {
      this.scroll.scrollTo(x, y, time);
    },
    finishPullUp() {
      this.scroll.finishPullUp();
    },
  },
  mounted() {
    //1 创建BScroll对象
    this.scroll = new BScroll(this.$refs.wrapper, {
      click: true,
      observeDOM: true,
      probeType: this.probeType,
      // pullUpLoad: this.pullUpLoad,
      pullUpLoad: true,

      observeImage: true,
      // mouseWheel: true,
    });
    // 2 监听滚动的位置
    this.scroll.on("scroll", (position) => {
      // console.log(position);
      this.$emit("scroll", position);
    });
    // 3 监听上拉加载更多
    this.scroll.on("pullingUp", () => {
      // console.log("pullingUp");
      this.$emit("pullingUp");
    });
  },
};
</script>
<style scoped>
.wrapper {
  position: absolute;
  left: 0;
  right: 0;
  top: 44px;
  bottom: 49px;
  overflow: hidden;
  /* background-color: red; */
}
.content {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
}
</style>